package com.echoesnet.echoesshortvideo.Repositories;

import com.echoesnet.echoesshortvideo.Api.HttpMethods;
import com.echoesnet.echoesshortvideo.Api.RequestHeader;
import com.echoesnet.echoesshortvideo.Beans.UserBean;
import com.echoesnet.echoesshortvideo.Constant.Api;
import com.google.gson.Gson;

import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.functions.Function;

/**
 * Copyright (C) 2018 科技发展有限公司
 * 完全享有此软件的著作权，违者必究
 * 负责数据处理
 *
 * @author ben
 * @version 1.0
 * @modifier
 * @createDate 2018/4/19 18:12
 * @description
 */

public class UserDetailRepository
{

    public void getUser(final String tUserId, Observer<UserBean> observer)
    {
        Map<String, Object> reqMap = RequestHeader.getCommonPartOfParam();
        reqMap.put(RequestHeader.OTHER_USER_ID, tUserId);
        HttpMethods.getInstance().startServerRequest(observer, new Function<String, UserBean>()
        {
            @Override
            public UserBean apply(String response) throws Exception
            {
                return new Gson().fromJson(response, UserBean.class);
            }
        },Api.USERC_QUERYUSERINFO, reqMap);
    }

    public void updateUserInfo(UserBean bean, Observer<String> observer)
    {
        Map<String, Object> reqMap = RequestHeader.getCommonPartOfParam();
        reqMap.put(RequestHeader.USER_INFO, new Gson().toJson(bean, UserBean.class));
        HttpMethods.getInstance().startServerRequest(observer, Api.USERC_UPDATEUSERINFO, reqMap, true);
    }
}
